Fix out-of-tree builds of OCaml components
authorHilko Bengen <bengen@debian.org>
Tue, 3 Apr 2018 15:07:49 +0000 (17:07 +0200)
committerHilko Bengen <bengen@debian.org>
Wed, 11 Apr 2018 07:53:14 +0000 (08:53 +0100)
- Add $(srcdir), $(builddir) to Makefiles where required
- Post-process ocamldep output
- generate ocaml/.depends

Gbp-Pq: Name 0012-Fix-out-of-tree-builds-of-OCaml-components.patch

20 files changed:
builder/Makefile.am
common/mlgettext/Makefile.am
common/mlpcre/Makefile.am
common/mlprogress/Makefile.am
common/mlstdutils/Makefile.am
common/mltools/Makefile.am
common/mlutils/Makefile.am
common/mlvisit/Makefile.am
common/mlxml/Makefile.am
customize/Makefile.am
daemon/Makefile.am
generator/Makefile.am
get-kernel/Makefile.am
ocaml-dep.sh.in
ocaml/Makefile.am
resize/Makefile.am
sparsify/Makefile.am
subdir-rules.mk
v2v/Makefile.am
v2v/test-harness/Makefile.am

index ceb3bce684c073b80cca7eb239acedcf3a1384fd..e5872bdd9ca976a6682f605f5f6761ba6db7a361 100644 (file)
@@ -142,11 +142,12 @@ bin_PROGRAMS += virt-builder virt-builder-repository
 
 virt_builder_SOURCES = $(SOURCES_C)
 virt_builder_CPPFLAGS = \
-       -I. \
+       -I$(builddir) -I$(srcdir) \
        -I$(top_builddir) \
        -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
        -I$(shell $(OCAMLC) -where) \
        -I$(top_srcdir)/gnulib/lib \
+       -I$(top_builddir)/common/utils \
        -I$(top_srcdir)/common/utils \
        -I$(top_srcdir)/lib
 virt_builder_CFLAGS = \
@@ -163,7 +164,7 @@ XOBJECTS = $(BOBJECTS:.cmo=.cmx)
 
 virt_builder_repository_SOURCES = $(REPOSITORY_SOURCES_C)
 virt_builder_repository_CPPFLAGS = \
-       -I. \
+       -I$(builddir) -I$(srcdir) \
        -I$(top_builddir) \
        -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
        -I$(shell $(OCAMLC) -where) \
@@ -446,7 +447,7 @@ CLEANFILES += \
        console-*.out
 
 # OCaml dependencies.
-.depend: *.mli *.ml osinfo_config.mli osinfo_config.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml osinfo_config.mli osinfo_config.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index 4cca6b4db09e3eae1228f71b0255d98e20f000ac..cdcea33ec560aba31a9157847b7bfa1b86281b10 100644 (file)
@@ -79,7 +79,7 @@ mlgettext.cmxa: $(XOBJECTS)
 endif
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index 4ff74cf9727c009ce8fb6e0628080aed966affad..f9699f5922a198df1e9efb0081b6242e4ac5aa4f 100644 (file)
@@ -122,7 +122,7 @@ check-valgrind:
        $(MAKE) VG="@VG@" check
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index f031a5a69ea0f19de557543525fe0ebb99d14139..be88ef2dee907876a1fee12206923d10f8c78ea7 100644 (file)
@@ -93,7 +93,7 @@ $(MLPROGRESS_CMA): $(OBJECTS) libmlprogress.a
            -o mlprogress
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index cc05c5a73fbc355247eb88bd978388db857c896f..e38230db8a7026232512109dc6ff54b0778d2ad3 100644 (file)
@@ -141,7 +141,7 @@ check-valgrind:
        $(MAKE) VG="@VG@" check
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index 2ea1fee8ff1a8afa3b57fb8d71fdc666f9a71c66..66b18f5dedf28fe5594d2618bcdb23079bbe0e9a 100644 (file)
@@ -253,7 +253,7 @@ check-valgrind:
        $(MAKE) VG="@VG@" check
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index 33d742f4c3cecaa65721994c62bd9a1ba3a1f44f..8627e5b10cc40a9d15b072357290539d6ea6fa95 100644 (file)
@@ -135,7 +135,7 @@ c_utils_unit_tests_LINK = \
          $(c_utils_unit_tests_THEOBJECTS) -o $@
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index 6902c9a2a99c9c95047ed6ba4be6ce10519d313a..add1fe56e87df37bf7bb4b102eba609ac152067c 100644 (file)
@@ -139,7 +139,7 @@ check-valgrind:
        $(MAKE) VG="@VG@" check
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index 083c7a64be40e68351bcc396e08a143e30cecabc..eab036b82f537d9220824f6b6824ab4c34a34804 100644 (file)
@@ -88,7 +88,7 @@ $(MLXML_CMA): $(OBJECTS) libmlxml.a
            -o mlxml
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index 7f18b2fc3488885557a86e6e1ff31f873fccbb70..efdd2722756387c13b721e12d6e508a19e015f20 100644 (file)
@@ -312,7 +312,7 @@ CLEANFILES += \
        settings-*.img
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index c534baab0cf47dd1b3444ff119a92b14997d2279..94ee866a0ed2c5158d70a34a7f2446e7bbe8a7ff 100644 (file)
@@ -318,11 +318,11 @@ XOBJECTS = $(BOBJECTS:.cmo=.cmx)
 
 OCAMLPACKAGES = \
        -package str,unix,hivex \
-       -I $(top_srcdir)/common/mlaugeas \
-       -I $(top_srcdir)/common/mlstdutils \
-       -I $(top_srcdir)/common/mlutils \
+       -I $(top_builddir)/common/mlaugeas \
+       -I $(top_builddir)/common/mlstdutils \
+       -I $(top_builddir)/common/mlutils \
        -I $(top_builddir)/common/utils/.libs \
-       -I $(top_srcdir)/common/mlpcre \
+       -I $(top_builddir)/common/mlpcre \
        -I $(top_builddir)/common/mlpcre/.libs \
        -I $(top_builddir)/gnulib/lib/.libs
 
@@ -356,7 +356,7 @@ camldaemon.o: $(OBJECTS)
            $(OBJECTS)
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index fba807f18ada6ee9c4f10ddc1f9470b3fe707b6b..c2d10966aa4ff15a545ac08217c70816d11585d3 100644 (file)
@@ -188,7 +188,7 @@ generator: $(objects)
            $^ -o $@
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index 03d4b9815f2c09ec3db908d965c4afc79b9e558a..81dfb48b42e311c046d7a7f0f92fc88fdc14a9db 100644 (file)
@@ -135,7 +135,7 @@ stamp-virt-get-kernel.pod: virt-get-kernel.pod
        touch $@
 
 # OCaml dependencies.
-.depend: *.ml *.mli
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index 92037b785fd2510989711851c9c04ca968171d5f..9bd35ba277a5f2a8912cf42f95e2170ce8360fe8 100755 (executable)
@@ -49,7 +49,12 @@ ocaml
 # Output file is always created in the current directory.
 output=.depend
 
-includes=""
+subdir=$(realpath --relative-to=@abs_top_builddir@ .)
+srcdir=$(realpath --relative-to=. @abs_top_srcdir@/${subdir})
+srcdir_re=$(realpath --relative-to=. @abs_top_srcdir@/${subdir} | sed 's/\./[.]/g')
+top_builddir=$(realpath --relative-to=. @abs_top_builddir@)
+
+includes="-I @abs_top_srcdir@/$subdir -I @abs_top_builddir@/$subdir"
 for i in $include_dirs; do
     includes="$includes -I @abs_top_srcdir@/$i -I @abs_top_builddir@/$i"
 done
@@ -58,7 +63,22 @@ rm -f $output $output-t
 
 echo "# OCaml dependencies generated by $0" > $output-t
 echo >> $output-t
-@OCAMLFIND@ ocamldep @OCAMLDEP_ALL@ @OCAMLDEP_ONE_LINE@ $includes "$@" >> $output-t
+
+# Rewrite paths
+# 1. Normalize absolute srcdir to relative path
+# 2. Object files (*.cm*, *.o), in srcdir: Rewrite to builddir
+# 3. Generated _config.ml in srcdir: Rewrite to builddir
+# 4. Other object files below abs_top_srcdir: rewrite to corresponding builddir
+# 5. Eliminate "./" prefix
+@OCAMLFIND@ ocamldep @OCAMLDEP_ALL@ @OCAMLDEP_ONE_LINE@ $includes "$@" \
+    | sed \
+          -e "s,@abs_top_srcdir@/${subdir},.,g" \
+          -e "s,\B${srcdir_re}/\\([^ ]*[.]\\)\\(cm[^ ]*\\|o\\),\\1\\2,g" \
+          -e "s,\B${srcdir_re}/\\([^ /]*_config[.]ml\\),\\1,g" \
+          -e "s,@abs_top_srcdir@/\\([^ ]*[.]\\)\\(cm[^ ]*\\|o\\),${top_builddir}/\\1\\2,g" \
+          -e 's,\(^\| \)./,\1,g' \
+    >> $output-t
+
 chmod -w $output-t
 
 mv $output-t $output
index b2af7d7e2d59aae0af0839c4dbff60db16581378..b0f2900f2e857026e57c014eb443108e60a41cde 100644 (file)
@@ -26,7 +26,6 @@ generator_built = \
 
 EXTRA_DIST = \
        $(generator_built) \
-       .depend \
        guestfs-c.c guestfs-c.h \
        html/.gitignore \
        META.in \
@@ -171,7 +170,7 @@ check-valgrind:
        $(MAKE) VG="@VG@" TESTS="$(test_progs_all)" check
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index e599e1142f1b8c64dd87abdf79936fd5caf4fc93..847fb313a787e8c98caf72de22e8e5fa1db69edb 100644 (file)
@@ -144,7 +144,7 @@ check-valgrind:
        $(MAKE) VG="@VG@" check
 
 # Dependencies.
-.depend: *.ml *.mli
+.depend: $(srcdir)/*.ml $(srcdir)/*.mli
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index 2f73f97a6756451b2abba9bb16c191c74ec4304b..2ab357a685d7d1518f6d2d7dd1f612986c854a20 100644 (file)
@@ -154,7 +154,7 @@ check-valgrind:
        $(MAKE) VG="@VG@" check
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index a2382aa08c6f92e097469256bf082bc7253dad16..ef3ba0941f3972aef4b83631c79efa7454a96a9f 100644 (file)
@@ -79,12 +79,12 @@ guestfs_am_v_jar = $(guestfs_am_v_jar_@AM_V@)
 guestfs_am_v_jar_ = $(guestfs_am_v_jar_@AM_DEFAULT_V@)
 guestfs_am_v_jar_0 = @echo "  JAR     " $@;
 
-%.cmi: %.mli
+%.cmi: $(srcdir)/%.mli
        $(guestfs_am_v_ocamlcmi)$(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
-%.cmo: %.ml
+%.cmo: $(srcdir)/%.ml
        $(guestfs_am_v_ocamlc)$(OCAMLFIND) ocamlc $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
 if HAVE_OCAMLOPT
-%.cmx: %.ml
+%.cmx: $(srcdir)/%.ml
        $(guestfs_am_v_ocamlopt)$(OCAMLFIND) ocamlopt $(OCAMLFLAGS) $(OCAMLPACKAGES) -c $< -o $@
 endif
 
index 3a978d72713390e17d6784c30bf7f74c26097142..341a735ab93cebe5a6d761f7a92b688b12755846 100644 (file)
@@ -536,7 +536,7 @@ v2v_unit_tests_LINK = \
          $(v2v_unit_tests_THEOBJECTS) -o $@
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
index 5c38a7266bee4ca757c627b27e3378d040b2fdbd..d69188969e423aa4b13d8ecf0759bf3d2900fcbb 100644 (file)
@@ -126,7 +126,7 @@ stamp-virt-v2v-test-harness.pod: virt-v2v-test-harness.pod
        touch $@
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
        $(top_builddir)/ocaml-dep.sh -I .. $^
 -include .depend